# !/usr/bin/env python
# -*- coding: utf-8 -*-
from django.http import JsonResponse
from django.shortcuts import render


def chart_list(request):
    """ 数据统计页面 """
    return render(request, "mytest/chart_list.html")


def chart_bar(request):
    """ 构造柱状图数据 """
    # 数据可以去数据库中获取
    legend_list = ["未完成", "已完成"]
    series_list = [
        {
            "name": '未完成',
            "type": 'bar',
            "data": [5, 20]
        }, {
            "name": '已完成',
            "type": 'bar',
            "data": [3, 16]
        }
    ]
    x_axis_list = ['需求', '缺陷']

    result = {
        "status": True,
        "data": {
            "legend_list": legend_list,
            "series_list": series_list,
            "xAxis_list": x_axis_list
        }
    }

    return JsonResponse(result)


def chart_pie(request):
    series_list = [
        {"value": 1048, "name": 'IT部门'},
        {"value": 735, "name": '运营'},
        {"value": 580, "name": '新媒体'}
    ]

    result = {
        "status": True,
        "data": {
            "series_list": series_list
        }
    }

    print(result)

    return JsonResponse(result)
